
using System;

using Mono.Collections.Generic;
using System.Diagnostics;
using System.Collections.Generic;

namespace Mono.Cecil
{

    [DebuggerDisplay("{FullName}")]
    public class TypeDefinitionRuntime : TypeDefinition
    {


        private TypeDefinition _base;
        private TypeDefinition _sealedType;


        public TypeDefinitionRuntime(TypeDefinition @base, TypeDefinition sealedType)
        {
            this._base = @base;
            this._sealedType = sealedType;
        }


        public override TypeAttributes Attributes
        {
            get { return _base.Attributes; }
            set { _base.Attributes = value; }
        }

        private TypeReference _baseType;
        public override TypeReference BaseType
        {
            get
            {
                if (_baseType == null && _base.BaseType != null)
                    _baseType = new TypeReferenceRuntime(_base.BaseType, _sealedType);

                return _baseType;
            }
            set
            {
                _base.BaseType = value;
                _baseType = null;
            }
        }

        public override bool HasLayoutInfo
        {
            get { return _base.HasLayoutInfo; }
        }

        public override short PackingSize
        {
            get
            {
                return _base.PackingSize;
            }
            set { _base.PackingSize = value; }
        }

        public override int ClassSize
        {
            get { return _base.ClassSize; }
            set { _base.ClassSize = value; }
        }

        public override bool HasInterfaces
        {
            get { return _base.HasInterfaces; }
        }

        public override Collection<TypeReference> Interfaces { get { return _base.Interfaces; } }

        public override bool HasNestedTypes { get { return _base.HasNestedTypes; } }

        public override Collection<TypeDefinition> NestedTypes { get { return _base.NestedTypes; } }

        #region GetMembers

        public override bool HasMethods { get { return _base.HasMethods; } }

        public override Collection<MethodDefinition> Methods { get { return _base.Methods; } }

        public override bool HasFields { get { return _base.HasFields; } }

        internal override Collection<FieldDefinition> Fields { get { return _base.Fields; } }

        public override bool HasEvents { get { return _base.HasEvents; } }

        public override Collection<EventDefinition> Events { get { return _base.Events; } }

        public override bool HasProperties { get { return _base.HasProperties; } }

        internal override Collection<PropertyDefinition> Properties { get { return _base.Properties; } }

        public override IEnumerable<MemberReference> GetMembers()
        {
            System.Reflection.MemberTypes memberType = System.Reflection.MemberTypes.Field | System.Reflection.MemberTypes.Method | System.Reflection.MemberTypes.Property;
            foreach (var item in GetMembers(memberType, string.Empty, _sealedType))
                yield return item;
        }

        public override IEnumerable<MemberReference> GetMembers(System.Reflection.MemberTypes memberType)
        {

            foreach (var item in GetMembers(memberType, string.Empty, _sealedType))
                yield return item;

        }

        public override IEnumerable<MemberReference> GetMembers(string name)
        {
            System.Reflection.MemberTypes memberType = System.Reflection.MemberTypes.Field | System.Reflection.MemberTypes.Method | System.Reflection.MemberTypes.Property;
            foreach (var item in GetMembers(memberType, name, _sealedType))
                yield return item;

        }

        public override IEnumerable<MemberReference> GetMembers(System.Reflection.MemberTypes memberType, string name)
        {

            foreach (var item in GetMembers(memberType, name, _sealedType))
                yield return item;

        }

        public override IEnumerable<MemberReference> GetMembers(System.Reflection.MemberTypes memberType, string name, TypeReference Sealedtype)
        {
            foreach (var item in _base.GetMembers(memberType, name, this))
                yield return item;
        }

        #endregion

        public override bool HasSecurityDeclarations { get { return _base.HasSecurityDeclarations; } }

        public override Collection<SecurityDeclaration> SecurityDeclarations { get { return _base.SecurityDeclarations; } }

        public override bool HasCustomAttributes { get { return _base.HasCustomAttributes; } }

        public override Collection<CustomAttribute> CustomAttributes { get { return _base.CustomAttributes; } }

        public override bool HasGenericParameters { get { return _base.HasGenericParameters; } }

        public override Collection<GenericParameter> GenericParameters { get { return _base.GenericParameters; } }

        #region TypeAttributes

        public override bool IsNotPublic
        {
            get { return _base.IsNotPublic; }
            set { _base.IsNotPublic = value; }
        }

        public override bool IsPublic
        {
            get { return _base.IsPublic; }
            set { _base.IsPublic = value; }
        }

        public override bool IsNestedPublic
        {
            get { return _base.IsNestedPublic; }
            set { _base.IsNestedPublic = value; }
        }

        public override bool IsNestedPrivate
        {
            get { return _base.IsNestedPrivate; }
            set { _base.IsNestedPrivate = value; }
        }

        public override bool IsNestedFamily
        {
            get { return _base.IsNestedFamily; }
            set { _base.IsNestedFamily = value; }
        }

        public override bool IsNestedAssembly
        {
            get { return _base.IsNestedAssembly; }
            set { _base.IsNestedAssembly = value; }
        }

        public override bool IsNestedFamilyAndAssembly
        {
            get { return _base.IsNestedFamilyAndAssembly; }
            set { _base.IsNestedFamilyAndAssembly = value; }
        }

        public override bool IsNestedFamilyOrAssembly
        {
            get { return _base.IsNestedFamilyOrAssembly; }
            set { _base.IsNestedFamilyOrAssembly = value; }
        }

        public override bool IsAutoLayout
        {
            get { return _base.IsAutoLayout; }
            set { _base.IsAutoLayout = value; }
        }

        public override bool IsSequentialLayout
        {
            get { return _base.IsSequentialLayout; }
            set { _base.IsSequentialLayout = value; }
        }

        public override bool IsExplicitLayout
        {
            get { return _base.IsExplicitLayout; }
            set { _base.IsExplicitLayout = value; }
        }

        public override bool IsClass
        {
            get { return _base.IsClass; }
            set { _base.IsClass = value; }
        }

        public override bool IsInterface
        {
            get { return _base.IsInterface; }
            set { _base.IsInterface = value; }
        }

        public override bool IsAbstract
        {
            get { return _base.IsAbstract; }
            set { _base.IsAbstract = value; }
        }

        public override bool IsSealed
        {
            get { return _base.IsSealed; }
            set { _base.IsSealed = value; }
        }

        public override bool IsSpecialName
        {
            get { return _base.IsSpecialName; }
            set { _base.IsSpecialName = value; }
        }

        public override bool IsImport
        {
            get { return _base.IsImport; }
            set { _base.IsImport = value; }
        }

        public override bool IsSerializable
        {
            get { return _base.IsSerializable; }
            set { _base.IsSerializable = value; }
        }

        public override bool IsAnsiClass
        {
            get { return _base.IsAnsiClass; }
            set { _base.IsAnsiClass = value; }
        }

        public override bool IsUnicodeClass
        {
            get { return _base.IsUnicodeClass; }
            set { _base.IsUnicodeClass = value; }
        }

        public override bool IsAutoClass
        {
            get { return _base.IsAutoClass; }
            set { _base.IsAutoClass = value; }
        }

        public override bool IsBeforeFieldInit
        {
            get { return _base.IsBeforeFieldInit; }
            set { _base.IsBeforeFieldInit = value; }
        }

        public override bool IsRuntimeSpecialName
        {
            get { return _base.IsRuntimeSpecialName; }
            set { _base.IsRuntimeSpecialName = value; }
        }

        public override bool HasSecurity
        {
            get { return _base.HasSecurity; }
            set { _base.HasSecurity = value; }
        }

        #endregion

        public override bool IsEnum
        {
            get { return _base.IsEnum; }
        }

        public override bool IsValueType { get { return _base.IsValueType; } }

        public override TypeDefinition DeclaringType
        {
            get { return _base.DeclaringType; }
            set { _base.DeclaringType = value; }
        }

        public override TypeDefinition Resolve()
        {
            return this;
        }



        #region TypeReference

        public override string Name
        {
            get { return _base.Name; }
            set { _base.Name = value; }
        }

        public override string Namespace
        {
            get { return _base.Namespace; }
            set { _base.Namespace = value; }
        }

        public override ModuleDefinition Module { get { return _base.Module; } }

        public IGenericParameterProvider Type { get { return this; } }

        public IGenericParameterProvider Method { get { return null; } }

        public GenericParameterType GenericParameterType { get { return GenericParameterType.Type; } }

        public override IMetadataScope Scope { get { return _base.Scope; } }

        public override bool IsNested { get { return _base.IsNested; } }

        public override string FullName { get { return _base.FullName; } }

        public override bool IsPrimitive { get { return _base.IsPrimitive; } }

        public override MetadataType MetadataType { get { return _base.MetadataType; } }

        public override TypeReference GetElementType() { return this; }

        public override System.Reflection.MemberTypes MemberType { get { return System.Reflection.MemberTypes.TypeInfo; } }

        public override int GetHashCode()
        {
            int r = this.Module.Assembly.Name.Name.GetHashCode();
            return r;
        }

        public override bool Equals(object obj)
        {
            bool r = _base.Equals(obj);
            return r;
        }

        public override string AssemblyQualifiedName { get { return _base.AssemblyQualifiedName; } }


        #endregion

    }

}
